﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Threading.Tasks;
using System.Reflection;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using SMK_Profiler_Core;

namespace SMK_Profiler_Service
{
    /// <summary>
    /// 
    /// </summary>
    public partial class SMK_Profiler_Service : ServiceBase
    {
        SMK_Profiler_DBEntities _smkDB = new SMK_Profiler_DBEntities();
        Microsoft.AnalysisServices.Trace _msaTrace = null;
        SortedList<string, Microsoft.AnalysisServices.Server> _msaServers;
        string _TraceName = string.Empty;
        /// <summary>
        /// 
        /// </summary>
        string _ServerName;
        /// <summary>
        /// 
        /// </summary>
        string[] _SQLServerName;
        string _AllTrace = string.Empty;
        SortedList<string, TraceEventStatistics> _servertraces = null;
        /// <summary>
        /// 
        /// </summary>
        public SMK_Profiler_Service()
        {
            InitializeComponent();
            //this.Icon.Text = ApplicationInfo.Title + " " + ApplicationInfo.Version.ToString() + " " + ApplicationInfo.CopyrightHolder.ToString();
            _ServerName = Properties.Settings.Default.ServerName;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="args"></param>
        protected override void OnStart(string[] args)
        {
            _TraceName = ApplicationInfo.ProductName + " " + System.Guid.NewGuid().ToString();
            //this.Icon.BalloonTipText = "Servcie Start ("+_TraceName+")" ;

            _OpenConnection(1);
            foreach (Microsoft.AnalysisServices.Server msaServer in _msaServers.Values)
            {
                msaServer.Refresh();
                if (msaServer.Traces.Contains(_TraceName))
                {
                    msaServer.Traces[_TraceName].Drop();
                }

                _msaTrace = msaServer.Traces.Add(_TraceName, _TraceName);

                //for (int i = 0; i <= this.listView1.SelectedItems.Count - 1; i++)
                //{
                //    string eventid = this.listView1.SelectedItems[i].Text;
                //    Microsoft.AnalysisServices.TraceEvent _msaTraceEvent = new Microsoft.AnalysisServices.TraceEvent((Microsoft.AnalysisServices.TraceEventClass)Enum.Parse(typeof(Microsoft.AnalysisServices.TraceEventClass), eventid, true));
                //    _msaTraceEvent = msaTraceColumns(_msaTraceEvent);
                //    _msaTrace.Events.Add(_msaTraceEvent);
                //}
                Microsoft.AnalysisServices.TraceEvent _msaTraceEvent = new Microsoft.AnalysisServices.TraceEvent(Microsoft.AnalysisServices.TraceEventClass.ProgressReportEnd);
                _msaTraceEvent = msaTraceColumns(_msaTraceEvent);
                _msaTrace.Events.Add(_msaTraceEvent);

                msaServer.Traces[_msaTrace.ID].OnEvent += new Microsoft.AnalysisServices.TraceEventHandler(_msaTrace_OnEvent);
                msaServer.Traces[_msaTrace.ID].Stopped += new Microsoft.AnalysisServices.TraceStoppedEventHandler(_msaTrace_Stopped);
                try
                {
                    _msaTrace.Update();
                }
                catch (Microsoft.AnalysisServices.OperationException aex)
                {
                    System.Diagnostics.Debug.WriteLine(aex.Message);
                    EventLog.WriteEntry(aex.Message);
                }
                try
                {
                    msaServer.Traces[_msaTrace.ID].Start();
                }
                catch (Microsoft.AnalysisServices.AmoException aex)
                {
                    System.Diagnostics.Debug.WriteLine(aex.Message);
                    EventLog.WriteEntry(aex.Message);
                }
            }
            EventLog.WriteEntry("Trace Started " + _TraceName);
            //this.Icon.ShowBalloonTip(1000);
        }
        /// <summary>
        /// 
        /// </summary>
        protected override void OnShutdown()
        {
            base.OnShutdown();
        }
        /// <summary>
        /// 
        /// </summary>
        protected override void OnStop()
        {
            if (_msaServers != null)
            {
                foreach (Microsoft.AnalysisServices.Server msaServer in _msaServers.Values)
                {
                    msaServer.Refresh();
                    if (msaServer.Traces.Contains(_TraceName))
                    {
                        msaServer.Traces[_TraceName].Drop();
                    }
                }
            }
            EventLog.WriteEntry("Trace Stopped " + _TraceName);
            //this.Icon.BalloonTipText = "Servcie Stop (" + _TraceName + ") ";
            //this.Icon.ShowBalloonTip(1000);
        }

        private void _OpenConnection(int ConnectionType)
        {
            if (ConnectionType == 1) //OLAP
            {

                    string strServername = _ServerName;
                    if (_ServerName.ToUpper() == "LOCALHOST" || _ServerName == ".")
                    {
                        strServername = Environment.MachineName;
                    }
                    if (_msaServers == null)
                    {
                        _msaServers = new SortedList<string, Microsoft.AnalysisServices.Server>();
                        _servertraces = new SortedList<string, TraceEventStatistics>();
                    }
                    Microsoft.AnalysisServices.Server msaServer = null;
                    if (_msaServers.ContainsKey(strServername))
                    {
                        msaServer = _msaServers.Values[_msaServers.IndexOfKey(strServername)];
                    }
                    else
                    {
                        msaServer = new Microsoft.AnalysisServices.Server();
                        _msaServers.Add(strServername, msaServer);
                        _servertraces.Add(strServername, new TraceEventStatistics(_ServerName));
                    }

                    if (msaServer == null)
                    {

                    }
                    if (!msaServer.Connected)
                    {
                        try
                        {
                            msaServer.Connect(Connections.OlapConnection(strServername));
                        }
                        catch (Microsoft.AnalysisServices.ConnectionException ex)
                        {
                            System.Diagnostics.Debug.WriteLine(ex.Message);
                            Microsoft.AnalysisServices.ConnectionExceptionCause _msacc = ex.ExceptionCause;
                            System.Diagnostics.Debug.WriteLine(_msacc.ToString());
                            Environment.Exit(-1);
                        }
                    }
                
            }
        }
        private void _msaTrace_OnEvent(object sender, Microsoft.AnalysisServices.TraceEventArgs e)
        {
            Nullable<int> eventClass = null;
            string activityID = null;
            string applicationName = null;
            string clientHostName = null;
            Nullable<int> clientProcessID = null;
            Nullable<int> connectionID = null;
            Nullable<System.DateTime> currentTime = null;
            string nTDomainName = null;
            string nTUserName = null;
            string requestID = null;
            Nullable<int> sPID = null;
            string serverName = null;
            Nullable<System.DateTime> startTime = null;
            Nullable<long> cPUTime = null;
            string databaseName = null;
            Nullable<long> duration = null;
            string nTCanonicalUserName = null;
            string requestProperties = null;
            string textData = null;
            Nullable<int> error = null;
            Nullable<int> eventSubclass = null;
            string sessionID = null;
            Nullable<int> severity = null;
            Nullable<int> success = null;
            Nullable<System.DateTime> endTime = null;
            string objectID = null;
            string objectName = null;
            string objectPath = null;
            string objectReference = null;
            Nullable<int> objectType = null;
            string objectTypeName = null;
            Nullable<long> integerData = null;
            Nullable<long> progressTotal = null;
            Nullable<int> jobID = null;
            string sessionType = null;
            string requestParameters = null;
            byte[] binaryData = null;

            System.Diagnostics.Debug.WriteLine(e.EventClass.ToString());
            if (_servertraces.ContainsKey(e.ServerName))
            {
                _servertraces.Values[_servertraces.IndexOfKey(e.ServerName)].AddTraceEvent(_TraceName, e);
            }

            try
            {
                #region Command Events Event Category
                if (e.EventClass == Microsoft.AnalysisServices.TraceEventClass.CommandBegin)
                {
                    eventClass = (int)e.EventClass;

                }
                if (e.EventClass == Microsoft.AnalysisServices.TraceEventClass.CommandEnd)
                {
                }
                #endregion
                #region Discover Events Event Category
                if (e.EventClass == Microsoft.AnalysisServices.TraceEventClass.DiscoverBegin)
                {
                }
                if (e.EventClass == Microsoft.AnalysisServices.TraceEventClass.DiscoverEnd)
                {
                }
                #endregion
                #region Discover Server State Event Category
                if (e.EventClass == Microsoft.AnalysisServices.TraceEventClass.ServerStateDiscoverBegin)
                {
                }
                if (e.EventClass == Microsoft.AnalysisServices.TraceEventClass.ServerStateDiscoverData)
                {
                }
                if (e.EventClass == Microsoft.AnalysisServices.TraceEventClass.ServerStateDiscoverEnd)
                {
                }
                #endregion
                #region Errors and Warnings Event Category
                if (e.EventClass == Microsoft.AnalysisServices.TraceEventClass.Error)
                {
                }
                #endregion
                #region File Load and Save Event Category
                if (e.EventClass == Microsoft.AnalysisServices.TraceEventClass.FileLoadBegin)
                {
                }
                if (e.EventClass == Microsoft.AnalysisServices.TraceEventClass.FileLoadEnd)
                {
                }
                if (e.EventClass == Microsoft.AnalysisServices.TraceEventClass.FileSaveBegin)
                {
                }
                if (e.EventClass == Microsoft.AnalysisServices.TraceEventClass.PageInBegin)
                {
                }
                if (e.EventClass == Microsoft.AnalysisServices.TraceEventClass.PageInEnd)
                {
                }
                if (e.EventClass == Microsoft.AnalysisServices.TraceEventClass.PageOutBegin)
                {
                }
                if (e.EventClass == Microsoft.AnalysisServices.TraceEventClass.PageOutEnd)
                {
                }
                #endregion
                #region Lock Events Category
                if (e.EventClass == Microsoft.AnalysisServices.TraceEventClass.Deadlock)
                {
                }
                if (e.EventClass == Microsoft.AnalysisServices.TraceEventClass.Locktimeout)
                {
                }
                if (e.EventClass == Microsoft.AnalysisServices.TraceEventClass.LockAcquired)
                {
                }
                if (e.EventClass == Microsoft.AnalysisServices.TraceEventClass.LockReleased)
                {
                }
                if (e.EventClass == Microsoft.AnalysisServices.TraceEventClass.LockWaiting)
                {
                }
                #endregion
                #region Notification Events Event Category
                if (e.EventClass == Microsoft.AnalysisServices.TraceEventClass.Notification)
                {
                }
                if (e.EventClass == Microsoft.AnalysisServices.TraceEventClass.UserDefined)
                {
                }
                #endregion
                #region Progress Reports Event Category
                if (e.EventClass == Microsoft.AnalysisServices.TraceEventClass.ProgressReportBegin)
                {
                    eventClass = (int)e.EventClass;
                    eventSubclass = (int)e.EventSubclass;
                    currentTime = (DateTime)e.CurrentTime;
                    startTime = (DateTime)e.StartTime;
                    jobID = Convert.ToInt32(e.JobID);
                    sessionType = e.SessionType;
                    objectID = e.ObjectID;
                    //objectType = Convert.ToInt32(e.ObjectType);
                    if (e.ObjectType != null)
                    {
                        objectTypeName = e.ObjectType.ToString();
                        objectType = (int)Enum.Parse(typeof(SMK_Profiler_MSAS_Types), objectTypeName.Replace(".", "_"));
                    }
                    else
                    {
                        objectTypeName = null;
                    }
                    objectName = e.ObjectName;
                    objectPath = e.ObjectPath;
                    objectReference = e.ObjectReference;
                    connectionID = Convert.ToInt32(e.ConnectionID);
                    databaseName = (string)e.DatabaseName;
                    nTUserName = (string)e.NTUserName;
                    clientProcessID = Convert.ToInt32(e.ClientProcessID);
                    applicationName = e.ApplicationName;
                    sessionID = e.SessionID;
                    nTCanonicalUserName = e.NTCanonicalUserName;
                    sPID = Convert.ToInt32(e.Spid);
                    textData = e.TextData;
                    serverName = e.ServerName;
                    //requestParameters = e.RequestParameters;
                    //requestProperties = e.RequestProperties;
                }
                if (e.EventClass == Microsoft.AnalysisServices.TraceEventClass.ProgressReportCurrent)
                {
                    eventClass = (int)e.EventClass;
                    eventSubclass = (int)e.EventSubclass;
                    currentTime = (DateTime)e.CurrentTime;
                    startTime = (DateTime)e.StartTime;
                    //endTime = (DateTime)e.EndTime;
                    //duration = e.Duration;
                    //cPUTime = e.CpuTime;
                    jobID = Convert.ToInt32(e.JobID);
                    sessionType = e.SessionType;
                    progressTotal = e.ProgressTotal;
                    integerData = e.IntegerData;
                    objectID = e.ObjectID;
                    //objectType = Convert.ToInt32(e.ObjectType);
                    if (e.ObjectType != null)
                    {
                        objectTypeName = e.ObjectType.ToString();
                        objectType = (int)Enum.Parse(typeof(SMK_Profiler_MSAS_Types), objectTypeName.Replace(".", "_"));
                    }
                    else
                    {
                        objectTypeName = null;
                    }
                    objectName = e.ObjectName;
                    objectPath = e.ObjectPath;
                    objectReference = e.ObjectReference;
                    ///*Error / Sucess Handling*/
                    //if (e.Success != null)
                    //{
                    //    success = (int)e.Success;
                    //}

                    //if (e.Error != null)
                    //{
                    //    error = Convert.ToInt32(e.Error);
                    //    if (!string.IsNullOrEmpty(e.Severity.ToString()))
                    //    {
                    //        severity = e.Severity;
                    //    }
                    //}
                    ///*Error / Sucess Handling*/
                    connectionID = Convert.ToInt32(e.ConnectionID);
                    databaseName = (string)e.DatabaseName;
                    nTUserName = (string)e.NTUserName;
                    clientProcessID = Convert.ToInt32(e.ClientProcessID);
                    applicationName = e.ApplicationName;
                    sessionID = e.SessionID;
                    nTCanonicalUserName = e.NTCanonicalUserName;
                    sPID = Convert.ToInt32(e.Spid);
                    textData = e.TextData;
                    serverName = e.ServerName;
                    //requestParameters = e.RequestParameters;
                    //requestProperties = e.RequestProperties;
                }
                if (e.EventClass == Microsoft.AnalysisServices.TraceEventClass.ProgressReportEnd)
                {
                    eventClass = (int)e.EventClass;
                    eventSubclass = (int)e.EventSubclass;
                    currentTime = (DateTime)e.CurrentTime;
                    startTime = (DateTime)e.StartTime;
                    endTime = (DateTime)e.EndTime;
                    duration = e.Duration;
                    cPUTime = e.CpuTime;
                    jobID = Convert.ToInt32(e.JobID);
                    sessionType = e.SessionType;
                    progressTotal = e.ProgressTotal;
                    integerData = e.IntegerData;
                    objectID = e.ObjectID;
                    //objectType = Convert.ToInt32(e.ObjectType);
                    if (e.ObjectType != null)
                    {
                        objectTypeName = e.ObjectType.ToString();
                        objectType = (int)Enum.Parse(typeof(SMK_Profiler_MSAS_Types), objectTypeName.Replace(".", "_"));
                    }
                    else
                    {
                        objectTypeName = null;
                    }
                    objectName = e.ObjectName;
                    objectPath = e.ObjectPath;
                    objectReference = e.ObjectReference;
                    /*Error / Sucess Handling*/
                    if (e.Success != null)
                    {
                        success = (int)e.Success;
                    }

                    if (e.Error != null)
                    {
                        error = Convert.ToInt32(e.Error);
                        if (!string.IsNullOrEmpty(e.Severity.ToString()))
                        {
                            severity = e.Severity;
                        }
                    }
                    /*Error / Sucess Handling*/
                    connectionID = Convert.ToInt32(e.ConnectionID);
                    databaseName = (string)e.DatabaseName;
                    nTUserName = (string)e.NTUserName;
                    clientProcessID = Convert.ToInt32(e.ClientProcessID);
                    applicationName = e.ApplicationName;
                    sessionID = e.SessionID;
                    nTCanonicalUserName = e.NTCanonicalUserName;
                    sPID = Convert.ToInt32(e.Spid);
                    textData = e.TextData;
                    serverName = e.ServerName;
                    //requestParameters = e.RequestParameters;
                    //requestProperties = e.RequestProperties;
                }
                if (e.EventClass == Microsoft.AnalysisServices.TraceEventClass.ProgressReportError)
                {
                    eventClass = (int)e.EventClass;
                    eventSubclass = (int)e.EventSubclass;
                    currentTime = (DateTime)e.CurrentTime;
                    startTime = (DateTime)e.StartTime;
                    endTime = (DateTime)e.EndTime;
                    duration = e.Duration;
                    //cPUTime = e.CpuTime;
                    jobID = Convert.ToInt32(e.JobID);
                    sessionType = e.SessionType;
                    progressTotal = e.ProgressTotal;
                    integerData = e.IntegerData;
                    objectID = e.ObjectID;
                    //objectType = Convert.ToInt32(e.ObjectType);
                    if (e.ObjectType != null)
                    {
                        objectTypeName = e.ObjectType.ToString();
                        objectType = (int)Enum.Parse(typeof(SMK_Profiler_MSAS_Types), objectTypeName.Replace(".", "_"));
                    }
                    else
                    {
                        objectTypeName = null;
                    }
                    objectName = e.ObjectName;
                    objectPath = e.ObjectPath;
                    objectReference = e.ObjectReference;
                    /*Error / Sucess Handling*/
                    //if (e.Success != null)
                    //{
                    //    success = (int)e.Success;
                    //}

                    if (e.Error != null)
                    {
                        error = Convert.ToInt32(e.Error);
                        if (!string.IsNullOrEmpty(e.Severity.ToString()))
                        {
                            severity = e.Severity;
                        }
                    }
                    /*Error / Sucess Handling*/
                    connectionID = Convert.ToInt32(e.ConnectionID);
                    databaseName = (string)e.DatabaseName;
                    //nTUserName = (string)e.NTUserName;
                    //clientProcessID = Convert.ToInt32(e.ClientProcessID);
                    //applicationName = e.ApplicationName;
                    sessionID = e.SessionID;
                    //nTCanonicalUserName = e.NTCanonicalUserName;
                    sPID = Convert.ToInt32(e.Spid);
                    textData = e.TextData;
                    serverName = e.ServerName;
                    //requestParameters = e.RequestParameters;
                    //requestProperties = e.RequestProperties;
                }
                #endregion
                #region Queries Events Category
                if (e.EventClass == Microsoft.AnalysisServices.TraceEventClass.QueryBegin)
                {
                    eventClass = (int)e.EventClass;
                    eventSubclass = (int)e.EventSubclass;
                    currentTime = (DateTime)e.CurrentTime;
                    startTime = (DateTime)e.StartTime;
                    connectionID = Convert.ToInt32(e.ConnectionID);
                    databaseName = (string)e.DatabaseName;
                    nTUserName = (string)e.NTUserName;
                    clientProcessID = Convert.ToInt32(e.ClientProcessID);
                    applicationName = e.ApplicationName;
                    sessionID = e.SessionID;
                    nTCanonicalUserName = e.NTCanonicalUserName;
                    sPID = Convert.ToInt32(e.Spid);
                    textData = e.TextData;
                    serverName = e.ServerName;
                    requestParameters = e.RequestParameters;
                    requestProperties = e.RequestProperties;
                }
                if (e.EventClass == Microsoft.AnalysisServices.TraceEventClass.QueryEnd)
                {
                    eventClass = (int)e.EventClass;
                    eventSubclass = (int)e.EventSubclass;
                    currentTime = (DateTime)e.CurrentTime;
                    startTime = (DateTime)e.StartTime;
                    endTime = (DateTime)e.EndTime;
                    duration = e.Duration;
                    cPUTime = e.CpuTime;
                    /*Error / Sucess Handling*/
                    if (e.Success != null)
                    {
                        success = (int)e.Success;
                    }

                    if (e.Error != null)
                    {
                        error = Convert.ToInt32(e.Error);
                        if (!string.IsNullOrEmpty(e.Severity.ToString()))
                        {
                            severity = e.Severity;
                        }
                    }
                    /*Error / Sucess Handling*/
                    connectionID = Convert.ToInt32(e.ConnectionID);
                    databaseName = (string)e.DatabaseName;
                    nTUserName = (string)e.NTUserName;
                    clientProcessID = Convert.ToInt32(e.ClientProcessID);
                    applicationName = e.ApplicationName;
                    sessionID = e.SessionID;
                    nTCanonicalUserName = e.NTCanonicalUserName;
                    sPID = Convert.ToInt32(e.Spid);
                    textData = e.TextData;
                    serverName = e.ServerName;
                    //requestParameters = e.RequestParameters;
                    //requestProperties = e.RequestProperties;
                }
                #endregion
                #region Query Processing Events Category
                if (e.EventClass == Microsoft.AnalysisServices.TraceEventClass.QueryCubeBegin)
                {
                }
                if (e.EventClass == Microsoft.AnalysisServices.TraceEventClass.QueryCubeEnd)
                {
                }
                if (e.EventClass == Microsoft.AnalysisServices.TraceEventClass.CalculateNonEmptyBegin)
                {
                }
                if (e.EventClass == Microsoft.AnalysisServices.TraceEventClass.CalculateNonEmptyCurrent)
                {
                }
                if (e.EventClass == Microsoft.AnalysisServices.TraceEventClass.CalculateNonEmptyEnd)
                {
                }
                if (e.EventClass == Microsoft.AnalysisServices.TraceEventClass.SerializeResultsBegin)
                {
                }
                if (e.EventClass == Microsoft.AnalysisServices.TraceEventClass.SerializeResultsCurrent)
                {
                }
                if (e.EventClass == Microsoft.AnalysisServices.TraceEventClass.SerializeResultsEnd)
                {
                }
                if (e.EventClass == Microsoft.AnalysisServices.TraceEventClass.ExecuteMdxScriptBegin)
                {
                }
                if (e.EventClass == Microsoft.AnalysisServices.TraceEventClass.ExecuteMdxScriptCurrent)
                {
                }
                if (e.EventClass == Microsoft.AnalysisServices.TraceEventClass.ExecuteMdxScriptEnd)
                {
                }
                if (e.EventClass == Microsoft.AnalysisServices.TraceEventClass.QueryDimension)
                {
                }
                if (e.EventClass == Microsoft.AnalysisServices.TraceEventClass.QuerySubcube)
                {
                }
                if (e.EventClass == Microsoft.AnalysisServices.TraceEventClass.QuerySubcubeVerbose)
                {
                }
                if (e.EventClass == Microsoft.AnalysisServices.TraceEventClass.GetDataFromAggregation)
                {
                }
                if (e.EventClass == Microsoft.AnalysisServices.TraceEventClass.GetDataFromCache)
                {
                }
                if (e.EventClass == Microsoft.AnalysisServices.TraceEventClass.VertiPaqSEQueryBegin)
                {
                }
                if (e.EventClass == Microsoft.AnalysisServices.TraceEventClass.VertiPaqSEQueryCacheMatch)
                {
                }
                if (e.EventClass == Microsoft.AnalysisServices.TraceEventClass.VertiPaqSEQueryEnd)
                {
                }
                if (e.EventClass == Microsoft.AnalysisServices.TraceEventClass.ResourceUsage)
                {
                }
                if (e.EventClass == Microsoft.AnalysisServices.TraceEventClass.DirectQueryBegin)
                {
                }
                if (e.EventClass == Microsoft.AnalysisServices.TraceEventClass.DirectQueryEnd)
                {
                }
                #endregion
                #region Security Audit Event Category
                if (e.EventClass == Microsoft.AnalysisServices.TraceEventClass.AuditLogin)
                {
                }
                if (e.EventClass == Microsoft.AnalysisServices.TraceEventClass.AuditLogout)
                {
                }
                if (e.EventClass == Microsoft.AnalysisServices.TraceEventClass.AuditServerStartsAndStops)
                {
                }
                if (e.EventClass == Microsoft.AnalysisServices.TraceEventClass.AuditObjectPermission)
                {
                }
                if (e.EventClass == Microsoft.AnalysisServices.TraceEventClass.AuditAdminOperations)
                {
                }
                #endregion
                #region Session Events Event Category
                if (e.EventClass == Microsoft.AnalysisServices.TraceEventClass.ExistingConnection)
                {
                }
                if (e.EventClass == Microsoft.AnalysisServices.TraceEventClass.ExistingSession)
                {
                }
                if (e.EventClass == Microsoft.AnalysisServices.TraceEventClass.SessionInitialize)
                {
                }
                #endregion
                #region Write to Function
                _smkDB.usp_Insert_ssas_trace_log
                   (
                  eventClass, activityID, applicationName, clientHostName, clientProcessID, connectionID, currentTime, nTDomainName, nTUserName, requestID, sPID, serverName, startTime, cPUTime, databaseName, duration, nTCanonicalUserName, requestProperties, textData, error, eventSubclass, sessionID, severity, success, endTime, objectID, objectName, objectPath, objectReference, objectType, integerData, progressTotal, jobID, sessionType, requestParameters, binaryData, objectTypeName
                   );
                #endregion
            }
            catch
            (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }
        }
        private void _msaTrace_Stopped(object sender, Microsoft.AnalysisServices.TraceStoppedEventArgs e)
        {
            System.Diagnostics.Debug.WriteLine(e.StopCause.ToString());
            if (e.StopCause == Microsoft.AnalysisServices.TraceStopCause.StoppedByException)
            {
                System.Diagnostics.Debug.WriteLine(e.Exception.Message);
            }
        }
        private Microsoft.AnalysisServices.TraceEvent msaTraceColumns(Microsoft.AnalysisServices.TraceEvent TraceEvent)
        {
            #region  Security Audit Data Columns
            //Event ID
            //Event Name
            //Event Description
            //1
            //Audit Login
            //Collects all new connection events since the trace was started, such as when a client requests a connection to a server running an instance of SQL Server.
            //2
            //Audit Logout
            //Collects all new disconnect events since the trace was started, such as when a client issues a disconnect command.
            //4
            //Audit Server Starts And Stops
            //Records service shut down, start, and pause activities.
            //18
            //Audit Object Permission Event
            //Records object permission changes.
            //19
            //Audit Admin Operations Event
            //Records server backup/restore/synchronize/attach/detach/imageload/imagesave.

            if (TraceEvent.EventID == Microsoft.AnalysisServices.TraceEventClass.AuditLogin) //1
            {
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.EventClass);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.CurrentTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.StartTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Severity);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Success);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Error);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ConnectionID);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.NTUserName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.NTDomainName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ClientHostName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ClientProcessID);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ApplicationName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.NTCanonicalUserName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ServerName);
            }
            if (TraceEvent.EventID == Microsoft.AnalysisServices.TraceEventClass.AuditLogout) //2
            {
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.EventClass);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.CurrentTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.EndTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Duration);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.CpuTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Success);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ConnectionID);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.NTUserName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.NTDomainName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ClientHostName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ClientProcessID);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ApplicationName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.NTCanonicalUserName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ServerName);
            }
            if (TraceEvent.EventID == Microsoft.AnalysisServices.TraceEventClass.AuditServerStartsAndStops) //4
            {
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.EventClass);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.EventSubclass);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.CurrentTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Severity);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Success);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Error);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.TextData);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ServerName);
            }
            if (TraceEvent.EventID == Microsoft.AnalysisServices.TraceEventClass.AuditObjectPermission) //18
            {
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.EventClass);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectID);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectType);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectPath);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectReference);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Severity);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Success);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Error);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ConnectionID);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.DatabaseName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.NTUserName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.NTDomainName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ClientHostName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ClientProcessID);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ApplicationName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.SessionID);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.NTCanonicalUserName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Spid);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.TextData);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ServerName);
            }

            if (TraceEvent.EventID == Microsoft.AnalysisServices.TraceEventClass.AuditAdminOperations) //19
            {
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.EventClass);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.EventSubclass);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Severity);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Success);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Error);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ConnectionID);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.DatabaseName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.NTUserName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.NTDomainName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ClientHostName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ClientProcessID);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ApplicationName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.SessionID);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.NTCanonicalUserName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Spid);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.TextData);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ServerName);
            }
            #endregion //Security Audit Data Columns
            #region Session Events Data Columns
            if (TraceEvent.EventID == Microsoft.AnalysisServices.TraceEventClass.ExistingConnection) //41
            {
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.EventClass);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.CurrentTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.StartTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ConnectionID);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.NTUserName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.NTDomainName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ClientHostName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ClientProcessID);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ApplicationName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Spid);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ServerName);
            }
            if (TraceEvent.EventID == Microsoft.AnalysisServices.TraceEventClass.ExistingSession) //42
            {
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.EventClass);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.CurrentTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.StartTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Duration);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.CpuTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ConnectionID);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.DatabaseName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.NTUserName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.NTDomainName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ClientHostName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ClientProcessID);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ApplicationName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.NTCanonicalUserName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Spid);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.TextData);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ServerName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.RequestProperties);
            }
            if (TraceEvent.EventID == Microsoft.AnalysisServices.TraceEventClass.SessionInitialize) //43
            {
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.EventClass);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.CurrentTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.StartTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ConnectionID);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.DatabaseName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.NTUserName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.NTDomainName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ClientHostName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ClientProcessID);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ApplicationName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.NTCanonicalUserName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Spid);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.TextData);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ServerName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.RequestProperties);
            }
            #endregion //Session Events Data Columns
            #region Query Processing Events Data Columns
            if (TraceEvent.EventID == Microsoft.AnalysisServices.TraceEventClass.QuerySubcube) //11
            {
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.EventClass);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.EventSubclass);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.CurrentTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.StartTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.EndTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Duration);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.CpuTime);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ProgressTotal);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.IntegerData);


                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectType);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectPath);

                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ConnectionID);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.DatabaseName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.SessionID);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.NTCanonicalUserName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Spid);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.TextData);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ServerName);
            }
            if (TraceEvent.EventID == Microsoft.AnalysisServices.TraceEventClass.QuerySubcubeVerbose) //12
            {
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.EventClass);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.EventSubclass);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.CurrentTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.StartTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.EndTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Duration);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.CpuTime);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ProgressTotal);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.IntegerData);


                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectType);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectPath);

                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ConnectionID);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.DatabaseName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.SessionID);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.NTCanonicalUserName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Spid);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.TextData);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ServerName);
            }
            if (TraceEvent.EventID == Microsoft.AnalysisServices.TraceEventClass.GetDataFromAggregation) //60
            {
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.EventClass);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.EventSubclass);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.CurrentTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.StartTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.EndTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Duration);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.CpuTime);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ProgressTotal);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.IntegerData);


                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectType);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectPath);

                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ConnectionID);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.DatabaseName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.SessionID);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.NTCanonicalUserName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Spid);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.TextData);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ServerName);
            }
            if (TraceEvent.EventID == Microsoft.AnalysisServices.TraceEventClass.GetDataFromCache) //61
            {
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.EventClass);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.EventSubclass);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.CurrentTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.StartTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.EndTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Duration);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.CpuTime);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ProgressTotal);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.IntegerData);


                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectType);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectPath);

                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ConnectionID);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.DatabaseName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.SessionID);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.NTCanonicalUserName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Spid);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.TextData);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ServerName);
            }
            if (TraceEvent.EventID == Microsoft.AnalysisServices.TraceEventClass.QueryCubeBegin) //70
            {
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.EventClass);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.CurrentTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.StartTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.EndTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Duration);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.CpuTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ProgressTotal);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.IntegerData);


                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectType);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectPath);

                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ConnectionID);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.DatabaseName);

                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.NTCanonicalUserName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Spid);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.TextData);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ServerName);
            }
            if (TraceEvent.EventID == Microsoft.AnalysisServices.TraceEventClass.QueryCubeEnd) //71
            {
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.EventClass);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.CurrentTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.StartTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.EndTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Duration);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.CpuTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ProgressTotal);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.IntegerData);


                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectType);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectPath);

                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ConnectionID);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.DatabaseName);

                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.NTCanonicalUserName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Spid);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.TextData);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ServerName);
            }
            if (TraceEvent.EventID == Microsoft.AnalysisServices.TraceEventClass.CalculateNonEmptyBegin) //72
            {
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.EventClass);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.CurrentTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.StartTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.EndTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Duration);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.CpuTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ProgressTotal);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.IntegerData);


                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectType);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectPath);

                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ConnectionID);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.DatabaseName);

                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.NTCanonicalUserName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Spid);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.TextData);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ServerName);
            }
            if (TraceEvent.EventID == Microsoft.AnalysisServices.TraceEventClass.CalculateNonEmptyCurrent) //73
            {
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.EventClass);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.EventSubclass);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.CurrentTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.StartTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.EndTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Duration);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.CpuTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ProgressTotal);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.IntegerData);


                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectType);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectPath);

                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ConnectionID);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.DatabaseName);

                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.NTCanonicalUserName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Spid);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.TextData);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ServerName);
            }
            if (TraceEvent.EventID == Microsoft.AnalysisServices.TraceEventClass.CalculateNonEmptyEnd) //74
            {
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.EventClass);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.CurrentTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.StartTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.EndTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Duration);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.CpuTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ProgressTotal);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.IntegerData);


                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectType);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectPath);

                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ConnectionID);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.DatabaseName);

                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.NTCanonicalUserName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Spid);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.TextData);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ServerName);
            }
            if (TraceEvent.EventID == Microsoft.AnalysisServices.TraceEventClass.SerializeResultsBegin) //75
            {
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.EventClass);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.CurrentTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.StartTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.EndTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Duration);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.CpuTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ProgressTotal);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.IntegerData);


                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectType);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectPath);

                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ConnectionID);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.DatabaseName);

                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.NTCanonicalUserName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Spid);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.TextData);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ServerName);
            }
            if (TraceEvent.EventID == Microsoft.AnalysisServices.TraceEventClass.SerializeResultsCurrent) //76
            {
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.EventClass);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.EventSubclass);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.CurrentTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.StartTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.EndTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Duration);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.CpuTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ProgressTotal);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.IntegerData);


                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectType);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectPath);

                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ConnectionID);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.DatabaseName);

                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.NTCanonicalUserName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Spid);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.TextData);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ServerName);
            }
            if (TraceEvent.EventID == Microsoft.AnalysisServices.TraceEventClass.SerializeResultsEnd) //77
            {
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.EventClass);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.CurrentTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.StartTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.EndTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Duration);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.CpuTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ProgressTotal);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.IntegerData);


                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectType);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectPath);

                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ConnectionID);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.DatabaseName);

                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.NTCanonicalUserName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Spid);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.TextData);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ServerName);
            }
            if (TraceEvent.EventID == Microsoft.AnalysisServices.TraceEventClass.ExecuteMdxScriptBegin) //78
            {
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.EventClass);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.EventSubclass);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.CurrentTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.StartTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.EndTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Duration);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.CpuTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ProgressTotal);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.IntegerData);


                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectType);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectPath);

                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ConnectionID);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.DatabaseName);

                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.NTCanonicalUserName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Spid);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.TextData);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ServerName);
            }
            if (TraceEvent.EventID == Microsoft.AnalysisServices.TraceEventClass.ExecuteMdxScriptCurrent) //79
            {
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.EventClass);

                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.CurrentTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.StartTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.EndTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Duration);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.CpuTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ProgressTotal);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.IntegerData);


                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectType);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectPath);

                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ConnectionID);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.DatabaseName);

                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.NTCanonicalUserName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Spid);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.TextData);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ServerName);
            }
            if (TraceEvent.EventID == Microsoft.AnalysisServices.TraceEventClass.ExecuteMdxScriptEnd) //80
            {
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.EventClass);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.EventSubclass);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.CurrentTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.StartTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.EndTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Duration);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.CpuTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ProgressTotal);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.IntegerData);


                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectType);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectPath);

                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ConnectionID);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.DatabaseName);

                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.NTCanonicalUserName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Spid);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.TextData);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ServerName);
            }
            if (TraceEvent.EventID == Microsoft.AnalysisServices.TraceEventClass.QueryDimension) //81
            {
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.EventClass);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.EventSubclass);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.CurrentTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.StartTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.EndTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Duration);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.CpuTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ProgressTotal);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.IntegerData);


                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectType);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectPath);

                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ConnectionID);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.DatabaseName);

                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.NTCanonicalUserName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Spid);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.TextData);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ServerName);
            }
            if (TraceEvent.EventID == Microsoft.AnalysisServices.TraceEventClass.VertiPaqSEQueryBegin) //82
            {
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.EventClass);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.EventSubclass);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.CurrentTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.StartTime);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.EndTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.JobID);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.SessionType);

                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectID);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectType);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectPath);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectReference);

                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ConnectionID);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.DatabaseName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.NTUserName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.NTDomainName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.SessionID);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ClientHostName);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ClientProcessID);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ApplicationName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.NTCanonicalUserName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Spid);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.TextData);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ServerName);
            }
            if (TraceEvent.EventID == Microsoft.AnalysisServices.TraceEventClass.VertiPaqSEQueryEnd) //83
            {
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.EventClass);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.EventSubclass);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.CurrentTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.StartTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.EndTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Duration);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.CpuTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.JobID);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.SessionType);

                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectID);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectType);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectPath);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectReference);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Severity);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Success);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Error);

                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ConnectionID);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.DatabaseName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.NTUserName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.NTDomainName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.SessionID);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ClientHostName);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ClientProcessID);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ApplicationName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.NTCanonicalUserName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Spid);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.TextData);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ServerName);
            }
            if (TraceEvent.EventID == Microsoft.AnalysisServices.TraceEventClass.ResourceUsage) //84
            {
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.EventClass);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.CurrentTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ConnectionID);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.DatabaseName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.NTUserName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.NTDomainName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.SessionID);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ClientProcessID);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ApplicationName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.NTCanonicalUserName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Spid);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.TextData);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ServerName);
            }
            if (TraceEvent.EventID == Microsoft.AnalysisServices.TraceEventClass.VertiPaqSEQueryCacheMatch) //85
            {
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.EventClass);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.EventSubclass);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.CurrentTime);

                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.JobID);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.SessionType);

                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectID);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectType);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectPath);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectReference);

                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ConnectionID);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.DatabaseName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.NTUserName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.NTDomainName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.SessionID);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ClientHostName);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ClientProcessID);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ApplicationName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.NTCanonicalUserName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Spid);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.TextData);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ServerName);
            }
            if (TraceEvent.EventID == Microsoft.AnalysisServices.TraceEventClass.DirectQueryBegin) //98
            {
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.EventClass);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.EventSubclass);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.CurrentTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.StartTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.EndTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Duration);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.CpuTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.JobID);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.SessionType);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.IntegerData);

                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectID);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectType);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectPath);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectReference);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Severity);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Success);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Error);

                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ConnectionID);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.DatabaseName);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.NTUserName);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.NTDomainName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.SessionID);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ClientHostName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ClientProcessID);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ApplicationName);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.NTCanonicalUserName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Spid);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.TextData);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ServerName);
            }
            if (TraceEvent.EventID == Microsoft.AnalysisServices.TraceEventClass.DirectQueryEnd) //99
            {
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.EventClass);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.EventSubclass);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.CurrentTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.StartTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.EndTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Duration);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.CpuTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.JobID);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.SessionType);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.IntegerData);

                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectID);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectType);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectPath);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectReference);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Severity);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Success);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Error);

                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ConnectionID);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.DatabaseName);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.NTUserName);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.NTDomainName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.SessionID);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ClientHostName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ClientProcessID);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ApplicationName);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.NTCanonicalUserName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Spid);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.TextData);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ServerName);
            }
            #endregion //Query Processing Events Data Columns
            #region Queries Events Data Columns
            if (TraceEvent.EventID == Microsoft.AnalysisServices.TraceEventClass.QueryBegin) //9
            {
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.EventClass);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.EventSubclass);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.CurrentTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.StartTime);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.EndTime);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Duration);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.CpuTime);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.JobID);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.SessionType);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.IntegerData);

                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectID);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectType);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectName);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectPath);
                ////TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectReference);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Severity);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Success);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Error);

                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ConnectionID);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.DatabaseName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.NTUserName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.NTDomainName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.SessionID);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ClientHostName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ClientProcessID);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ApplicationName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.NTCanonicalUserName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Spid);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.TextData);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ServerName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.RequestProperties);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.RequestParameters);
            }
            if (TraceEvent.EventID == Microsoft.AnalysisServices.TraceEventClass.QueryEnd) //10
            {
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.EventClass);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.EventSubclass);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.CurrentTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.StartTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.EndTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Duration);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.CpuTime);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.JobID);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.SessionType);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.IntegerData);

                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectID);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectType);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectName);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectPath);
                ////TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectReference);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Severity);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Success);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Error);

                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ConnectionID);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.DatabaseName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.NTUserName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.NTDomainName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.SessionID);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ClientHostName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ClientProcessID);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ApplicationName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.NTCanonicalUserName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Spid);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.TextData);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ServerName);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.RequestProperties);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.RequestParameters);
            }
            #endregion //Queries Events Data Columns
            #region Progress Reports Data Columns
            if (TraceEvent.EventID == Microsoft.AnalysisServices.TraceEventClass.ProgressReportBegin) //5
            {
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.EventClass);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.EventSubclass);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.CurrentTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.StartTime);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.EndTime);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Duration);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.CpuTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.JobID);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.SessionType);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.IntegerData);

                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectID);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectType);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectPath);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectReference);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Severity);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Success);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Error);

                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ConnectionID);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.DatabaseName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.NTUserName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.NTDomainName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.SessionID);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ClientHostName);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ClientProcessID);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ApplicationName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.NTCanonicalUserName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Spid);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.TextData);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ServerName);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.RequestProperties);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.RequestParameters);
            }
            if (TraceEvent.EventID == Microsoft.AnalysisServices.TraceEventClass.ProgressReportCurrent) //7
            {
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.EventClass);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.EventSubclass);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.CurrentTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.StartTime);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.EndTime);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Duration);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.CpuTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.JobID);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.SessionType);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ProgressTotal);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.IntegerData);

                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectID);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectType);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectPath);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectReference);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Severity);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Success);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Error);

                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ConnectionID);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.DatabaseName);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.NTUserName);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.NTDomainName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.SessionID);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ClientHostName);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ClientProcessID);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ApplicationName);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.NTCanonicalUserName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Spid);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.TextData);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ServerName);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.RequestProperties);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.RequestParameters);
            }
            if (TraceEvent.EventID == Microsoft.AnalysisServices.TraceEventClass.ProgressReportEnd) //6
            {
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.EventClass);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.EventSubclass);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.CurrentTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.StartTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.EndTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Duration);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.CpuTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.JobID);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.SessionType);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ProgressTotal);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.IntegerData);

                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectID);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectType);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectPath);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectReference);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Severity);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Success);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Error);

                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ConnectionID);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.DatabaseName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.NTUserName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.NTDomainName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.SessionID);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ClientHostName);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ClientProcessID);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ApplicationName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.NTCanonicalUserName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Spid);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.TextData);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ServerName);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.RequestProperties);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.RequestParameters);
            }
            if (TraceEvent.EventID == Microsoft.AnalysisServices.TraceEventClass.ProgressReportError) //8
            {
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.EventClass);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.EventSubclass);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.CurrentTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.StartTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.EndTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Duration);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.CpuTime);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.JobID);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.SessionType);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ProgressTotal);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.IntegerData);

                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectID);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectType);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectPath);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectReference);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Severity);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Success);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Error);

                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ConnectionID);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.DatabaseName);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.NTUserName);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.NTDomainName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.SessionID);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ClientHostName);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ClientProcessID);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ApplicationName);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.NTCanonicalUserName);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Spid);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.TextData);
                TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ServerName);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.RequestProperties);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.RequestParameters);
            }
            if (TraceEvent.EventID == Microsoft.AnalysisServices.TraceEventClass.ProgressReportEnd) //6
            {
                ////TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.EventClass);
                ////TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.EventSubclass);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.CurrentTime);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.StartTime);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.EndTime);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Duration);
                ////TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.CpuTime);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.JobID);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.SessionType);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ProgressTotal);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.IntegerData);

                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectID);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectType);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectName);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectPath);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ObjectReference);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Severity);
                ////TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Success);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Error);

                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ConnectionID);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.DatabaseName);
                ////TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.NTUserName);
                ////TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.NTDomainName);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.SessionID);
                ////TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ClientHostName);
                ////TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ClientProcessID);
                ////TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ApplicationName);
                ////TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.NTCanonicalUserName);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.Spid);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.TextData);
                //TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.ServerName);
                ////TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.RequestProperties);
                ////TraceEvent.Columns.Add(Microsoft.AnalysisServices.TraceColumn.RequestParameters);
            }
            #endregion //Progress Reports Data Columns
            return TraceEvent;
        }

        // Convert an object to a byte array
        private byte[] ObjectToByteArray(Object obj)
        {
            if (obj == null)
                return null;
            BinaryFormatter bf = new BinaryFormatter();
            MemoryStream ms = new MemoryStream();
            bf.Serialize(ms, obj);
            return ms.ToArray();
        }

        // Convert a byte array to an Object
        private Object ByteArrayToObject(byte[] arrBytes)
        {
            MemoryStream memStream = new MemoryStream();
            BinaryFormatter binForm = new BinaryFormatter();
            memStream.Write(arrBytes, 0, arrBytes.Length);
            memStream.Seek(0, SeekOrigin.Begin);
            Object obj = (Object)binForm.Deserialize(memStream);
            return obj;
        }

    }

    static public class ApplicationInfo
    {
        public static Version Version { get { return Assembly.GetCallingAssembly().GetName().Version; } }

        public static string Title
        {
            get
            {
                object[] attributes = Assembly.GetCallingAssembly().GetCustomAttributes(typeof(AssemblyTitleAttribute), false);
                if (attributes.Length > 0)
                {
                    AssemblyTitleAttribute titleAttribute = (AssemblyTitleAttribute)attributes[0];
                    if (titleAttribute.Title.Length > 0) return titleAttribute.Title;
                }
                return System.IO.Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().CodeBase);
            }
        }

        public static string ProductName
        {
            get
            {
                object[] attributes = Assembly.GetCallingAssembly().GetCustomAttributes(typeof(AssemblyProductAttribute), false);
                return attributes.Length == 0 ? "" : ((AssemblyProductAttribute)attributes[0]).Product;
            }
        }

        public static string Description
        {
            get
            {
                object[] attributes = Assembly.GetCallingAssembly().GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false);
                return attributes.Length == 0 ? "" : ((AssemblyDescriptionAttribute)attributes[0]).Description;
            }
        }

        public static string CopyrightHolder
        {
            get
            {
                object[] attributes = Assembly.GetCallingAssembly().GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false);
                return attributes.Length == 0 ? "" : ((AssemblyCopyrightAttribute)attributes[0]).Copyright;
            }
        }

        public static string CompanyName
        {
            get
            {
                object[] attributes = Assembly.GetCallingAssembly().GetCustomAttributes(typeof(AssemblyCompanyAttribute), false);
                return attributes.Length == 0 ? "" : ((AssemblyCompanyAttribute)attributes[0]).Company;
            }
        }

    }

    static public class Connections
    {
        public static string OlapConnection(string ServerName)
        {
            return "Provider=MSOLAP;Integrated Security=SSPI;Persist Security Info=False;Data Source=" + ServerName + ";Application Name=" + ApplicationInfo.ProductName + ";Workstation ID=" + Environment.MachineName;
        }
    }
}
